parameters:
  buildConfig: ''
  archType: ''
  osGroup: ''
  osSubgroup: ''
  name: ''
  helixType: '(unspecified)'
  container: ''
  crossBuild: false
  strategy: ''
  pool: ''

  # arcade-specific parameters
  condition: ''
  continueOnError: false
  dependsOn: ''
  displayName: ''
  timeoutInMinutes: ''
  enableMicrobuild: ''
  gatherAssetManifests: false
  disableComponentGovernance: ''

  variables: {} ## any extra variables to add to the defaults defined below

jobs:
- template: /eng/common/templates/job/job.yml
  parameters:

    name: ${{ parameters.name }}
    displayName: ${{ parameters.displayName }}
    container: ${{ parameters.container }}
    condition: ${{ parameters.condition }}
    dependsOn:
      - ${{ if ne(parameters.dependsOn, '') }}:
        - ${{ parameters.dependsOn }}

    timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
    continueOnError: ${{ parameters.continueOnError }}

    # Send telemetry for all builds
    enableTelemetry: true
    helixRepo: 'dotnet/runtime'
    helixType: ${{ parameters.helixType }}

    enableMicrobuild: ${{ parameters.enableMicrobuild }}
    enablePublishUsingPipelines: true

    strategy: ${{ parameters.strategy }}

    pool: ${{ parameters.pool }}

    workspace:
      clean: all

    ${{ if eq(parameters.osGroup, 'linux') }}:
      agentOs: Ubuntu
    ${{ if eq(parameters.osGroup, 'freebsd') }}:
      agentOs: FreeBSD
    ${{ if in(parameters.osGroup, 'osx', 'ios') }}:
      agentOs: MacOS
    ${{ if eq(parameters.osGroup, 'windows') }}:
      agentOs: windows

    # Component governance does not work on musl machines
    ${{ if eq(parameters.osSubGroup, '_musl') }}:
      disableComponentGovernance: true
    ${{ else }}:
      disableComponentGovernance: ${{ parameters.disableComponentGovernance }}

    # Setting this results in the arcade job template including a step
    # that gathers asset manifests and publishes them to pipeline
    # storage. Only relevant for build jobs.
    enablePublishBuildAssets: ${{ parameters.gatherAssetManifests }}

    variables:
    - name: buildConfig
      value: ${{ parameters.buildConfig }}

    - name: _BuildConfig
      value: ${{ parameters.buildConfig }}

    - ${{ if and(eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')) }}:
      - name: _HelixSource
        value: official/dotnet/runtime/$(Build.SourceBranch)
    - ${{ if and(eq(variables['System.TeamProject'], 'public'), eq(variables['Build.Reason'], 'PullRequest')) }}:
      - name: _HelixSource
        value: pr/dotnet/runtime/$(Build.SourceBranch)
    - ${{ if and(eq(variables['System.TeamProject'], 'public'), ne(variables['Build.Reason'], 'PullRequest')) }}:
      - name: _HelixSource
        value: ci/dotnet/runtime/$(Build.SourceBranch)

    - name: crossArg
      value: ''
    - ${{ if eq(parameters.crossBuild, true) }}:
      - name: crossArg
        value: '-cross'

    - ${{ each variable in parameters.variables }}:
      - ${{insert}}: ${{ variable }}

    steps:
    - ${{ if eq(parameters.osGroup, 'windows') }}:
      - template: /eng/pipelines/common/templates/disable-vsupdate-or-failfast.yml

    - checkout: self
      clean: true
      fetchDepth: $(checkoutFetchDepth)

    - ${{ parameters.steps }}
